using System;
using System.Drawing;
using Lime;

namespace Clandestine.Graphics
{
	internal class FramebufferTexture : Texture
	{
		private Size size;
		public override Size Size { get { return size; } }
	
		internal FramebufferTexture (Graphics graphics, string identifier, Size size, bool linearInterpolaiton, bool keepAlive = false)
			: base(graphics, identifier, linearInterpolaiton, keepAlive)
		{
			base.createNewGlTexture();
			this.size = size;
			
			// Extra texture stuff
			base.Graphics.BlockRendering();
			base.Graphics.WindowInternal.MakeContextCurrent();
			// If you start getting random garbage from VRam displayed as your framebuffer texture 
			// (i.e. because you don't render to it/before you do), look here! We don't copy anything to the vram.
			GL.TexImage2D(TextureTarget.Texture2D, 0, (int)PixelInternalFormat.Rgba8, this.Size.Width, this.Size.Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero); 
			base.Graphics.WindowInternal.ReleaseContext();
			base.Graphics.UnblockRendering();
		}
	}
}

